package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    @Select("select count(*) from student")
    Long count();


    Page<Student> list();

    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, create_time, update_time)" +
            "values(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void save(Student student);

    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    @Update("update student set name=#{name},no=#{no}, gender=#{gender}, phone=#{phone}, id_card=#{idCard}, is_college=#{isCollege}, address=#{address}, degree=#{degree}, graduation_date=#{graduationDate}, violation_count=#{violationCount},violation_score=#{violationScore}, clazz_id=#{clazzId}, create_time=#{createTime}, update_time=#{updateTime} where id = #{id}")
    void update(Student student);

    void deleteById(List<Integer> ids);

    @Select("select violation_count from student where id = #{id}")
    Integer getViolationCount(Integer id);

    @Update("update student set violation_count = #{newCount}, violation_score = violation_score+#{score} where id = #{id}")
    void addViolation(Integer id, Integer newCount, Integer score);

    @MapKey("clazzName")
    List<Map<String, Object>> studentClazzDataMap();

    @MapKey("degree")
    List<Map<String, Object>> getStudentDegreeData();
}
